import { ref } from 'vue'
export function useMove(name: string) {
  let isKeyDown = ref<boolean>(false)
  let dinatesX = ref<number>(0)
  let dinatesY = ref<number>(0)
  const mousedown = (event) => {
    isKeyDown.value = true
    dinatesX.value = event.x
    dinatesY.value = event.y

    document.onmousemove = (ev) => {
      if (isKeyDown.value) {
        const x = ev.screenX - dinatesX.value
        const y = ev.screenY - dinatesY.value
        //给主进程传入坐标
        let data = {
          appX: x,
          appY: y
        }
        window.electron.ipcRenderer.invoke('render-to-main', {
          name: name,
          data
        })
      }
    }
    document.onmouseup = () => {
      isKeyDown.value = false
    }
  }

  return { mousedown }
}
